package com.dmcb.trade.business.crawlers.article;

import com.dmcb.trade.business.constants.CrawlConstant;
import com.dmcb.trade.business.entities.Article;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.nodes.Document;
import org.springframework.stereotype.Service;

/**
 * 东方网文章编辑
 * Created by Administrator on 2016/5/6.
 */
@Service
public class DongFangParser extends BaseParser {

    /**
     * 网站URL网址
     *
     * @return 链接
     */
    @Override
    protected String url() {
        return CrawlConstant.DONGFANG_URL;
    }

    /**
     * 获取标题选择器
     *
     * @return 标题选择器
     */
    @Override
    protected String titleSelect() {
        return "div.J-title_detail>h1,div.article>h1.tit,div#biaoti,h1>span,h1.title";
    }

    /**
     * 获取日期选择器
     *
     * @return 发布日期选择器
     */
    @Override
    protected String dateSelect() {
        return "span#pubtime_baidu,div.fl>i";
    }

    /**
     * 获取正文内容选择器
     *
     * @return 正文内容选择器
     */
    @Override
    protected String bodySelect() {
        return "div#J-contain_detail_cnt,div#sectionleft";

    }

    /**
     * 获取作者选择器
     *
     * @return 作者选择器
     */
    @Override
    protected String authorNameSelect() {
        return "div.share_cnt_p>div.fl>a";
    }

    @Override
    protected void setAuthorName(Document doc, Article article) {
        String authorName=doc.select("div.fl>i").last().text();
        if (StringUtils.isNotBlank(authorName)){
            article.setAuthorName(authorName);
        }
    }

    /**
     * 获取封面选择器
     *
     * @return 封面选择器
     */
    @Override
    protected String coverSelect() {
        return "div#zw>p img[src]";
    }

    @Override
    protected String platform() {
        return "东方网";
    }
}
